package com.yiwei.zxp.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.api.model.SellCommentLabelModel;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class BussinessCommentTopAdapter extends ItemAdapter<SellCommentLabelModel.DatasBean, BussinessCommentTopAdapter.DefaultHolder> {


    public BussinessCommentTopAdapter(Context context) {
        super(context);
    }

    private int selectPoi = 0;

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_bussiness_comment_top, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        SellCommentLabelModel.DatasBean item = getItem(position);
        holder.txtSign.setText(item.name + "(" + item.num + ")");

        if (selectPoi == position) {
            holder.txtSign.setBackgroundResource(R.drawable.bg_comment_top_check);
            holder.txtSign.setTextColor(0xffFFFFFF);
        } else {
            holder.txtSign.setBackgroundResource(R.drawable.bg_comment_top_uncheck);
            holder.txtSign.setTextColor(0xffFF0030);
        }

        holder.txtSign.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPoi = position;
                if (onChooseListener != null) {
                    onChooseListener.onClick(item.keyword);
                }
                notifyDataSetChanged();
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_sign)
        TextView txtSign;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onClick(String keyword);

    }
}
